package top.zuli.package01.class06;

public class Clock {
    //1.定义秒针
    int second;
    //2.定义分钟针
    int minute;
    //4.定义小时针
    int hour;
    //5.定义运行秒针方法
    void runSecond(){
        second++;
        if(second==60) {
            second = 0;
            //minute++;
            runMinute();
        }
    }
    //6.定义分钟针运行
    void runMinute() {
        minute++;
        if(minute==60) {
            minute=0;
            //hour++;
            runHour();
        }
    }
    //7.定义小时
    void runHour() {
        hour++;
        if(hour==24) {
            hour = 0;
        }
    }
    public static void main(String[] args) {
        //1.创建钟表对象
        Clock clock = new Clock();
        //2.初始化值
        clock.second = 10;
        clock.minute = 51;
        clock.hour = 15;
        //3.打印时钟
        while(true) {
            //4.后面详细讲这个代码,这里只是测试,让程序听1000毫秒在执行
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("时钟："+clock.hour+":"+clock.minute+":"+clock.second);
            clock.runSecond();
        }
    }
}
